﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AppSerwis.ViewModel
{
    public abstract class ViewModelBase : INotifyPropertyChanged
    {

        private Dictionary<string, bool> _validProperties = new Dictionary<string,bool>();
        protected Dictionary<string, bool> ValidProperties
        {
            get { return this._validProperties; }            
        }

        private bool _allPropertiesValid = false;
        public bool AllPropertiesValid
        { 
            get { return _allPropertiesValid; }
            set
            {
                if (_allPropertiesValid != value)
                {
                    _allPropertiesValid = value;
                    NotifyPropertyChanged("AllPropertiesValid");
                }
            }
           }

        protected void ValidateProperties()
        {
            foreach (bool isValid in _validProperties.Values)
            {
                if (isValid == false)
                {
                    this.AllPropertiesValid = false;
                    return;
                }
            }
            this.AllPropertiesValid = true;
        }


        public event PropertyChangedEventHandler PropertyChanged;

        public void NotifyPropertyChanged(string propertyName)
        {
            if(PropertyChanged != null)
                PropertyChanged(this,new PropertyChangedEventArgs(propertyName));
        }
    }
}
